/*
 * GAssociation.java
 * Created on 19 juin 2007
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2007, Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hockeo.vhbase.data.dao.assoc;


import java.util.List;
import java.util.Locale;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.hockeo.vhbase.data.dao.GAbstractDao;
import com.hockeo.vhbase.data.dao.contest.GContest;

/**
 * Base class for national and international hockey association.
 *
 * @version $Id$
 * @author jjanke
 */
@Entity
@Table( name = "m_association" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn( name = "type", discriminatorType = DiscriminatorType.STRING )
public abstract class GAssociation extends GAbstractDao
{
  @Id
  @Column( name = "id" )
  private String         d_strId;

  @Column( name = "impl_class" )
  private String         d_strImplClass;

  @Column( name = "prepared" )
  private boolean        d_fPrepared;

  @Column( name = "image100_id" )
  private int            d_nImage100Id;

  @OneToMany( mappedBy = "d_association" )
  @OrderBy( "d_nCategory" )
  private List<GContest> d_listContests;

  /** Parameterless default constructor. */
  protected GAssociation()
  {}

  public String getImplClass()
  {
    return d_strImplClass;
  }

  /**
   * Indicates whether this association has been prepared for the season. E.g. all league
   * promotions/relegations have been carried out.
   */
  public boolean isPrepared()
  {
    return d_fPrepared;
  }

  /**
   * Sets the "prepared" flag.
   *
   * @param prepared indicates whether this association has been prepared for the season
   */
  public void setPrepared( boolean prepared )
  {
    d_fPrepared = prepared;
  }

  public int getImage100Id()
  {
    return d_nImage100Id;
  }

  public List<GContest> getContests()
  {
    return d_listContests;
  }

  public String getId()
  {
    return d_strId;
  }

  public String getId( Locale locale )
  {
    return translate( getId(), locale );
  }

  /*
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals( Object obj )
  {
    try
    {
      return d_strId.equals( ( (GAssociation) obj ).getId() );
    }
    catch ( Exception ex ) // especially ClassCastException(s) may happen
    {
      return false;
    }
  }

  /*
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode()
  {
    return d_strId.hashCode();
  }

  /*
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString()
  {
    return d_strId;
  }
}
